// ==UserScript==
// @name        New script - ataclass.cn
// @namespace   Violentmonkey Scripts
// @match       https://www.ataclass.cn/player/study/index
// @grant       none
// @version     1.0
// @author      -#vidplayer_component_66050BC3-06C0-4D12-9F5E-960222F7CB7C
// @description 2022/1/15 下午8:36:28
// ==/UserScript==
(function(){
  
  
  function click_btn(){
    var finish_btn = document.getElementById("btn_submit");
    finish_btn.click();
  }
 
  
  //点击下一个视频
  function click_next(count){
    s = count + 2;
    var next_work = document.querySelector("div[data-jhx-res=" + s + "]");
    next_work.click();
  }
  var finish_btn = document.getElementById("btn_submit");

  console.log("按钮文字是：" + finish_btn.innerText);
  var work_list = document.getElementsByClassName("cell flash section");
  console.log(work_list);
  
  //找到当前播放视频
  var active_cla = document.querySelector("#list_chapter > div.cell.flash.section.active");
  var active_count = active_cla.getAttribute("data-jhx-res");
  console.log("当前视频值：" + active_count);
  //alert(active_cla.getAttribute("data-jhx-res")); 
        
  //休息
  function sleep(times){
    var now = new Date();
    var exitTime = now.getTime() + times;
    
    while(true){
      now = new Date();
      if (now.getTime() > exitTime )
        return;
      
    }

  }      
  
  //检测时间 执行点击下一个视频
  function check_time(){
    var current_time = document.querySelector("#vidplayer_component_3A21A4F4-29EE-4FF3-AC60-6E44FF1B9F70 > span.current-time").innerText;
    var end_time = document.querySelector("#list_chapter > div.cell.flash.section.active > span.meta > span.time").innerText;
    console.log("当前视频时长： " + end_time);
    while(true){
      if (current_time===end_time) {
        console.log("视频已结束，点击下一个视频！");
        click_next(active_count);
      }
    
        sleep(5000);
    } 
  }
  check_time();
  
})();
